package com.demo.udf;

import com.demo.config.SpringContextUtil;
import com.demo.service.MyUdfService;
import lombok.extern.slf4j.Slf4j;
import net.hasor.dataql.DimUdf;
import net.hasor.dataql.Hints;
import net.hasor.dataql.Udf;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 自定义 udf,需要在 DatawayModule 添加以下配置代码，否则会出现注入为 null 问题
 * // udf/udfSource/import 指令 的类型创建委托给 spring
 * QueryApiBinder queryBinder = apiBinder.tryCast(QueryApiBinder.class);
 * queryBinder.bindFinder(Finder.TYPE_SUPPLIER.apply(this));
 */
@Slf4j
@DimUdf("myNameUdf")
@Service
public class MyNameUdf implements Udf {

    @Resource
    private MyUdfService myUdfService;

    @Override
    public Object call(Hints readOnly, Object... params) {
        log.info("获取当前服务信息: " + myUdfService.myName());
        return "张三";
    }
}